<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of membre
 *
 * @author AHAMADA
 */
class partenaire extends CI_Controller {
     
     function __construct()
     {
        parent::__construct();
        $this->load->database();
        $this->load->library('session');
        $this->load->library(array('ion_auth','form_validation'));
        $this->load->helper(array('form', 'url','html'));
        $this->data = $this->ion_auth->user()->row();
       
         
     }
     
    public function id($id = ''){
        
          $this->load->model("partenaire_model");
          $data['title'] = "Mon partenaire"; // Capitalize the first letter
          $data["partenaire"] = $this->partenaire_model->getPartenaire($id);
          $data["list_equipement"] = $this->partenaire_model->getPartenaireEquipement($id);
          $data["list_marque"] =     $this->partenaire_model->getPartenaireMarque($id);
 
        
          $this->load->view('templates/header', $this->data);
          $this->load->view('pages/partenaire', $data);
          $this->load->view('templates/footer', $this->data);
    }
    
    
    public function description($id = ''){
        
         $this->load->model("partenaire_model");
          $data['title'] = "Mon partenaire"; // Capitalize the first letter
          $data["partenaire"] = $this->partenaire_model->getPartenaire($id);
          $data["list_equipement"] = $this->partenaire_model->getPartenaireEquipement($id);
          $data["list_marque"] =     $this->partenaire_model->getPartenaireMarque($id);
 
        
          $this->load->view('templates/header', $this->data);
          $this->load->view('pages/partenaire_description', $data);
          $this->load->view('templates/footer', $this->data);
    }
    
    
    public function privilege($id = ''){
        
          $this->load->model("partenaire_model");
          $this->load->model("Privilege_model");
          $data['title'] = "Mon partenaire"; // Capitalize the first letter
          $data["partenaire"] = $this->partenaire_model->getPartenaire($id);
          $data["privilege"] = $this->partenaire_model->getPrivilegeByUserId($id);
          $data["list_equipement"] = $this->partenaire_model->getPartenaireEquipement($id);
          $data["list_marque"] =     $this->partenaire_model->getPartenaireMarque($id);
 
        
          $this->load->view('templates/header', $this->data);
          $this->load->view('pages/partenaire_privilege', $data);
          $this->load->view('templates/footer', $this->data);
    }
    
     public function location($id = ''){
        
         $this->load->model("partenaire_model");
          $data['title'] = "Mon partenaire"; // Capitalize the first letter
          $data["partenaire"] = $this->partenaire_model->getPartenaire($id);
          $data["list_equipement"] = $this->partenaire_model->getPartenaireEquipement($id);
          $data["list_marque"] =     $this->partenaire_model->getPartenaireMarque($id);
 
        
          $this->load->view('templates/header', $this->data);
          $this->load->view('pages/partenaire_location', $data);
          $this->load->view('templates/footer', $this->data);
    }
    
    
         public function soin($id = ''){
        
          $this->load->model("partenaire_model");
          $this->load->model("soin_model");
          $data['title'] = "Mon partenaire"; // Capitalize the first letter
          $data["partenaire"] = $this->partenaire_model->getPartenaire($id);
          $data["soin"] = $this->soin_Model->getSoinByUserId($id);
          $data["list_equipement"] = $this->partenaire_model->getPartenaireEquipement($id);
          $data["list_marque"] =     $this->partenaire_model->getPartenaireMarque($id);
          $data["soin"] = $this->soin_Model->getSoinByUserId($id);
          
          $this->load->view('templates/header', $this->data);
          $this->load->view('pages/partenaire_soin', $data);
          $this->load->view('templates/footer', $this->data);
    }
    
    
     public function avis($id = ''){
        
         $this->load->model("partenaire_model");
         $this->load->model("commentaire_Model");
          $data['title'] = "Mon partenaire"; // Capitalize the first letter
          $data["partenaire"] = $this->partenaire_model->getPartenaire($id);
          $data["list_equipement"] = $this->partenaire_model->getPartenaireEquipement($id);
          $data["list_marque"] =     $this->partenaire_model->getPartenaireMarque($id);
          $data["commentaire"] =     $this->Commentaire_Model->getCommentaireByUserId($id);
 
  
          $this->load->view('templates/header', $this->data);
          $this->load->view('pages/partenaire_avis', $data);
          $this->load->view('templates/footer', $this->data);
    }
    
    
     public function home()
     {
        $page = 'main';
        if ( ! file_exists('application/frontend/views/partenaire/'.$page.'.php'))
        {
                // Whoops, we don't have a page for that!
                show_404();
        }
        $data['title'] = ucfirst($page); // Capitalize the first letter

     
        
        if (!$this->ion_auth->logged_in())
        {
                redirect('/', 'refresh');
        }
        else
        {
            $this->load->view('templates/header', $this->data);
            $this->load->view('partenaire/'.$page, $this->data);
            $this->load->view('templates/footer', $this->data);
        }
        
     }   
     
     public function equipement()
     {
        if (!$this->ion_auth->logged_in())
        {
                redirect('/', 'refresh');
        }else{
            $this->load->model("partenaire_model");
            $partenaire = $this->partenaire_model->getPartenaireByUserId($this->data->id);
            $data["list_equipement"] = $this->partenaire_model->getPartenaireEquipement($partenaire->id);
           
            $this->load->view('templates/header', $this->data);
            $this->load->view('partenaire/equipement', $data);
            $this->load->view('templates/footer', $this->data);
        }
          
     }
     
     public function marque()
     {
        if (!$this->ion_auth->logged_in())
        {
                redirect('/', 'refresh');
        }else{
            $this->load->model("partenaire_model");
            $this->load->model("marque_model"); //partenaire_model
            $partenaire = $this->partenaire_model->getPartenaireByUserId($this->data->id);
            $data["list_marque"] = $this->partenaire_model->getPartenaireMarque($partenaire->id);
      
            $this->load->view('templates/header', $this->data);
            $this->load->view('partenaire/marque', $data);
            $this->load->view('templates/footer', $this->data);
        }
     }
     
     public function information()
     {
                 if (!$this->ion_auth->logged_in())
        {
                redirect('/', 'refresh');
        }else{
      
          $this->load->model("partenaire_model");
          $data['title'] = "Information Partenaire"; // Capitalize the first letter
          //echo $this->data->id;exit;
          $data["partenaire"] = $this->partenaire_model->getPartenaireByUserId($this->data->id);
          //print_r($data);
          //exit;
          $this->load->view('templates/header', $this->data);
          $this->load->view('partenaire/information', $data);
          $this->load->view('templates/footer', $this->data);
        }
     }
     
     public function mes_privileges()
     {
                 if (!$this->ion_auth->logged_in())
        {
                redirect('/', 'refresh');
        }else{
           $this->load->view('templates/header', $this->data);
            $this->load->view('partenaire/privilege', $this->data);
            $this->load->view('templates/footer', $this->data);
        }
     }
     
     public function carte_soin()
     {
                 if (!$this->ion_auth->logged_in())
        {
                redirect('/', 'refresh');
        }else{
           $this->load->view('templates/header', $this->data);
            $this->load->view('partenaire/soin', $this->data);
            $this->load->view('templates/footer', $this->data);
        }
     }
     
     public function contact(){
        if (!$this->ion_auth->logged_in())
        {
                redirect('/', 'refresh');
        }else{
            $this->load->helper(array('form', 'url'));
            $this->load->library('form_validation');
            $this->form_validation->set_error_delimiters('<span class="error">', '</span>');
            $this->form_validation->set_rules('adresse1', 'Adresse', 'trim|required');
            $this->form_validation->set_rules('adresse2', 'Adresse', 'trim|required');
            $this->form_validation->set_rules('codepostal', 'Code Postal', 'trim|required|min_length[5]');
            $this->form_validation->set_rules('ville', 'Ville', 'trim|required');
            $this->form_validation->set_rules('pays', 'Pays', 'trim|required');
            $this->form_validation->set_rules('telephone', 'Telephone', 'trim|required|is_numeric|min_length[10]|max_length[10]');
            $this->form_validation->set_rules('fax', 'Fax', 'trim|required|is_numeric|min_length[10]|max_length[10]');
            
            $this->load->model("partenaire_model");
            $data["partenaire"] = $this->partenaire_model->getPartenaireByUserId($this->data->id);
         
            if ($this->form_validation->run() == FALSE)
            {
                $this->load->view('templates/header', $this->data);
                $this->load->view('partenaire/contact', $data);
                $this->load->view('templates/footer', $this->data);
            }
            else{
               $data["resultat"] = $this->partenaire_model->updatePartenaire($this->data->id);
               $data["partenaire"] = $this->partenaire_model->getPartenaireByUserId($this->data->id);
               if ($data["resultat"]){
                   $this->load->view('templates/header', $this->data);
                   $this->load->view('partenaire/contact', $data);
                   $this->load->view('templates/footer', $this->data);
                }
            }
        }
     }
     
     public function changePassword(){
        
        if (!$this->ion_auth->logged_in())
        {
                redirect('/', 'refresh');
        }else{
            $this->form_validation->set_error_delimiters('<span class="error">', '</span>');
            $this->form_validation->set_rules('oldpassword', 'Ancien mot de passe', 'required');
            $this->form_validation->set_rules('newpassword', 'Nouveau de mot de passe', 'required|min_length[' . $this->config->item('min_password_length', 'ion_auth') . ']|max_length[' . $this->config->item('max_password_length', 'ion_auth') . ']|matches[confirmation]');
            $this->form_validation->set_rules('confirmation', 'Confirmation mot de passe', 'required');
            if ($this->form_validation->run() == false)
            {
                $data["resultat"]="";
                $this->load->view('templates/header', $this->data);
                $this->load->view('partenaire/password', $data);
                $this->load->view('templates/footer', $this->data);
            }else{
                 $identity = $this->session->userdata($this->config->item('identity', 'ion_auth'));
                 $change = $this->ion_auth->change_password($identity, $this->input->post('oldpassword'), $this->input->post('newpassword'));
                 
                 if ($change)
			{
				//if the password was successfully changed
                                $data["resultat"] = "<div style='color:green'>Mise à jour du mot de passe</div>";
                                
                                 $this->load->view('templates/header', $this->data);
                $this->load->view('partenaire/password', $data);
                $this->load->view('templates/footer', $this->data);
			}
			else
			{
				$data["resultat"] = "<div style='color:red'>Mot de passe non mise à jour, reessayer</div>";
				
                                 $this->load->view('templates/header', $this->data);
                $this->load->view('partenaire/password', $data);
                $this->load->view('templates/footer', $this->data);
			}
                }
        }
         
     }
     
      public function cartesoin(){
                if (!$this->ion_auth->logged_in())
        {
                redirect('/', 'refresh');
        }else{
            $this->load->view('templates/header', $this->data);
            $this->load->view('partenaire/cartesoin', $this->data);
            $this->load->view('templates/footer', $this->data);
        }
         
     }
      public function image(){
                if (!$this->ion_auth->logged_in())
        {
                redirect('/', 'refresh');
        }else{
            $this->load->view('templates/header', $this->data);
            $this->load->view('partenaire/image', $this->data);
            $this->load->view('templates/footer', $this->data);
        }
         
     }
     
     public function madescription(){
        if (!$this->ion_auth->logged_in())
        {
                redirect('/', 'refresh');
        }else{
            $this->load->helper(array('form', 'url'));
            $this->load->library('form_validation');
            $this->form_validation->set_error_delimiters('<span class="error">', '</span>');
            $this->form_validation->set_rules('horaires', 'Horaires', 'trim|required');
            $this->form_validation->set_rules('description', 'Description', 'trim|required');
           
            $this->load->model("partenaire_model");
            $data["partenaire"] = $this->partenaire_model->getPartenaireByUserId($this->data->id);
         
            if ($this->form_validation->run() == FALSE)
            {

                $this->load->view('templates/header', $this->data);
                $this->load->view('partenaire/description', $data);
                $this->load->view('templates/footer', $this->data);
            }
            else{
               $data["resultat"] = $this->partenaire_model->updatePartenaireDescription($this->data->id);
               $data["partenaire"] = $this->partenaire_model->getPartenaireByUserId($this->data->id);
               if ($data["resultat"]){

                   $this->load->view('templates/header', $this->data);
                   $this->load->view('partenaire/description', $data);
                   $this->load->view('templates/footer', $this->data);
                }
            }
        }
         
     }
      public function offreprivilege(){
         if (!$this->ion_auth->logged_in())
        {
                redirect('/', 'refresh');
        }else{
            $this->load->view('templates/header', $this->data);
            $this->load->view('partenaire/privilege', $this->data);
            $this->load->view('templates/footer', $this->data);
        }
      }
     
     
}
     
?>